<?php

namespace Tbf\Bundle\DatabaseBundle\ListQuery;

use Tbf\Bundle\DatabaseBundle\ListQuery\ConditionalExpress\ConditionalExpressInterface;
use Tbf\Component\Arrays\ArrayFunction;

class ListQuery
{
    protected $page=1;
    protected $page_size=10;
    /** @var  ConditionalExpressInterface */
    protected $where;
    /** @var  OrderExpress[] */
    protected $order=array();
    /** @var bool */
    protected $isPageResult = true;
    /**
     * 默认 表别名
     * @var string
     */
    protected $table_alias;
    public function setOrder($order)
    {
        $this->order = $order;
    }

    /**
     * @param OrderExpress $order
     * @return $this
     */
    public function addOrder(OrderExpress $order){
        $this->order[] = $order;
    }
    /**
     * @return OrderExpress[]
     */
    public function getOrder()
    {
        return $this->order;
    }

    /**
     * @return OrderExpress
     */
    public function getFirstOrder(){
        return ArrayFunction::firstValue($this->order);
    }

    public function setPage($page)
    {
        $this->page = $page;
    }

    public function getPage()
    {
        return $this->page;
    }

    public function setPageSize($page_size)
    {
        $this->page_size = $page_size;
    }

    public function getPageSize()
    {
        return $this->page_size;
    }

    /**
     * @param \Tbf\Bundle\DatabaseBundle\ListQuery\ConditionalExpress\ConditionalExpressInterface $where
     */
    public function setWhere(ConditionalExpressInterface $where)
    {
        $this->where = $where;
    }

    /**
     * @return \Tbf\Bundle\DatabaseBundle\ListQuery\ConditionalExpress\ConditionalExpressInterface
     */
    public function getWhere()
    {
        return $this->where;
    }
    /**
     * @param boolean $isPageResult
     */
    public function setIsPageResult($isPageResult)
    {
        $this->isPageResult = $isPageResult;
    }

    /**
     * @return boolean
     */
    public function getIsPageResult()
    {
        return $this->isPageResult;
    }

    /**
     * @param string $table_alias
     */
    public function setTableAlias($table_alias)
    {
        $this->table_alias = $table_alias;
    }

    /**
     * @return string
     */
    public function getTableAlias()
    {
        return $this->table_alias;
    }

}
